package com.zy.factory;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpRequest;

// 自定义请求拦截器
//@Component
public class AddHeaderGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {
    @Override
    public GatewayFilter apply(NameValueConfig config) {
        return (exchange, chain) -> {
            ServerHttpRequest changeRequest = exchange.getRequest().mutate().header(config.getName(), config.getValue()).build();
            exchange.mutate().request(changeRequest).build();
            return chain.filter(exchange);
        };
    }
}
